<?php
class Document{
	private $id;
	private $parentCatId;
	private $is_default;
	private $url;
	private $infos;
	private $TypeDocument;
//TODO: add typeDocument property
	function __construct($id) {

		if (is_int($id)){
			if($id >= 0){
				$this->id=$id;
			}else{
				throw new FieldFormatException($_SESSION['translator']->idVal);
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->idInt);
		}
	}
	public function getId(){
		return $this->id;
	}
	public function setTypeDocument($TypeDocument){
		if(is_a($TypeDocument, 'TypeDocument')){
			$this->TypeDocument = $TypeDocument;
		}
		else{
			throw new FieldFormatException("not a TypeDocument");
		}
	}
	public function getTypeDocument(){
		return $this->TypeDocument;
	}
	public function getTooltip($iso){
		$tooltip = "";
		foreach ($this->getInfos() as $Docinf){
			if(strtolower($Docinf->getLangue()->getIso()) == strtolower($iso)){
				$tooltip = $Docinf->getTooltip();
			}
		}
		return $tooltip;
	}
	public function getInfo($iso){
		$label = "";
		foreach ($this->getInfos() as $Docinf){

			if(strtolower($Docinf->getLangue()->getIso()) == strtolower($iso)){
				$label = $Docinf->getLabel();
			}
		}
		return $label;
	}
	public function getInfos(){
		return $this->infos;
	}

	public function setInfos($infoTab){
		if(is_array($infoTab)){
			$bool = true;
			foreach ($infoTab as $info){
				if  (!is_a($info, 'DocumentInfo')){
					$bool=false;
				}
			}
			if (!$bool){
				throw new FieldFormatException($_SESSION['translator']->listEx." DocumentInfo");
			}else{
				$this->infos=$infoTab;
			}
		}else{
			throw new FieldFormatException($_SESSION['translator']->arrayErr);
		}
	}
	
	public function setParentCategorieId($parentCatId){
		if (is_int($parentCatId)){
			$this->parentCatId = $parentCatId;
		}else{
			throw new FieldFormatException($_SESSION['translator']->idInt);
		}
	}
	public function getParentCategorieId(){
		return $this->parentCatId;
	}

	public function setUrl($url){
		$this->url = $url;
	}
	public function getUrl(){
		return $this->url;
	}
	public function isDefault(){
		return $this->is_default;
	}
	public function setDefault($bool){
		if($bool==1 || $bool == 0){
			$this->is_default = $bool;
		}else{
			throw new FieldFormatException($_SESSION['translator']->boolErr);
		}
	}
}
?>